import axios from '@/libs/http'
import qs from 'qs'

/**
 * 分页查询角色
 */
export const queryRolePage = data => {
  return axios({
    method: 'post',
    url: '/auth/role',
    data: data
  })
}

/**
 * 检查角色是否已存在
 */
export const checkRole = data => {
  return axios({
    method: 'post',
    url: '/auth/checkRole',
    data: data
  })
}

/**
 * 添加角色
 */
export const addRole = data => {
  return axios({
    method: 'post',
    url: '/auth/role?action=add',
    data: data
  })
}

/**
 * 更新角色
 */
export const updateRole = data => {
  return axios({
    method: 'post',
    url: '/auth/role?action=upd',
    data: data
  })
}

/**
 * 删除角色
 */
export const deleteRole = roleId => {
  let data = {roleId: roleId}
  return axios({
    method: 'post',
    url: '/auth/role?action=del',
    data: qs.stringify(data)
  })
}

/**
 * 获取角色菜单数据
 */
export const getRoleMenuData = roleId => {
  let data = {roleId: roleId}
  return axios({
    method: 'post',
    url: '/auth/role/menu',
    data: qs.stringify(data)
  })
}

/**
 * 分配角色菜单权限
 */
export const setRoleMenu = data => {
  return axios({
    method: 'post',
    url: '/auth/role/menu?action=auth',
    data: data
  })
}

/**
 * 查询已有权限id
 */
export const getPermissionIds = roleId => {
  return axios({
    method: 'post',
    url: '/auth/role/permissions',
    data: qs.stringify({roleId})
  })
}

/**
 * 分配角色功能权限
 */
export const setRolePermission = data => {
  return axios({
    method: 'post',
    url: '/auth/role/permissions?action=auth',
    data: data
  })
}
